home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS2.ZIP / RNEWS / EXPIRE.C next >
C/C++ Source or Header  |  1993-07-12  |  20KB  |  540 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    e x p i r e . c                                                 */
  3. /*                                                                    */
  4. /*    Expire old news articles for UUPC/extended                      */
  5. /*                                                                    */
  6. /*    Copyright (c) 1992-1993 by Kendra Electronic Wonderworks, all   */
  7. /*    rights reserved except those explicitly granted by the UUPC/    */
  8. /*    extended license.                                               */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*
  12.  *    $Id: expire.c 1.5 1993/07/13 01:13:32 ahd Exp $
  13.  *
  14.  *    $Log: expire.c $
  15.  * Revision 1.5  1993/07/13  01:13:32  ahd
  16.  * Drop unused stater.h header
  17.  *
  18.  * Revision 1.4  1993/04/05  04:32:19  ahd
  19.  * Add timestamp, size to information returned by directory searches
  20.  *
  21.  * Revision 1.3  1992/11/25  12:59:17  ahd
  22.  * Modifiy summery messages
  23.  *
  24.  */
  25.  
  26. /*--------------------------------------------------------------------*/
  27. /*                        System include files                        */
  28. /*--------------------------------------------------------------------*/
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34. #include <time.h>
  35. #include <limits.h>
  36.  
  37. /*--------------------------------------------------------------------*/
  38. /*                    UUPC/extended include files                     */
  39. /*--------------------------------------------------------------------*/
  40.  
  41. #include "lib.h"
  42. #include "active.h"
  43. #include "dater.h"
  44. #include "getopt.h"
  45. #include "hlib.h"
  46. #include "import.h"
  47. #include "importng.h"
  48. #include "logger.h"
  49. #include "uundir.h"
  50. #include "pushpop.h"
  51. #include "timestmp.h"
  52.  
  53. currentfile();
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                          Global Variables                          */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. #define ONE_DAY (60L*60L*24L)
  60.  
  61. /*--------------------------------------------------------------------*/
  62. /*                        Internal prototypes                         */
  63. /*--------------------------------------------------------------------*/
  64.  
  65. static boolean numeric( char *start);
  66.  
  67. static void ExpireAll( const time_t expire_date,
  68.                        const time_t archive_date );
  69.  
  70. static void  ExpireGroup( const char *group,
  71.                       const time_t expire_date,
  72.                       const time_t archive_date );
  73.  
  74. static void ExpireOneGroup( struct grp *cur_grp,
  75.                       const time_t expire_date,
  76.                       const time_t archive_date );
  77.  
  78. static void ExpireDirectory( struct grp *cur_grp,
  79.                       const time_t expire_date,
  80.                       const char *directory,
  81.                       const char *archive );
  82.  
  83. static boolean numeric( char *start);
  84.  
  85. static void usage( void );
  86.  
  87. long total_articles_purged   = 0;
  88. long total_articles_archived = 0;
  89. long total_articles_kept     = 0;
  90. long total_bytes_purged   = 0;
  91. long total_bytes_archived = 0;
  92. long total_bytes_kept     = 0;
  93.  
  94. /*--------------------------------------------------------------------*/
  95. /*    m a i n                                                         */
  96. /*                                                                    */
  97. /*    Main program                                                    */
  98. /*--------------------------------------------------------------------*/
  99.  
  100. void main( int argc, char **argv)
  101. {
  102.    int c;
  103.    extern char *optarg;
  104.    extern int   optind;
  105.    char *group = NULL;
  106.  
  107.    time_t expire_period  = 7; /* Seven days visible to users         */
  108.    time_t archive_period = 0; /* Seven days after expiring in arch   */
  109.  
  110.    time_t expire_date;
  111.    time_t archive_date;
  112.  
  113. /*--------------------------------------------------------------------*/
  114. /*     Report our version number and date/time compiled               */
  115. /*--------------------------------------------------------------------*/
  116.  
  117.    debuglevel = 1;
  118.    banner( argv );
  119.  
  120. #if defined(__CORE__)
  121.    copywrong = strdup(copyright);
  122.    checkref(copywrong);
  123. #endif
  124.  
  125. /*--------------------------------------------------------------------*/
  126. /*        Process our arguments                                       */
  127. /*--------------------------------------------------------------------*/
  128.  
  129.    while ((c = getopt(argc, argv, "e:a:g:x:n:")) !=  EOF)
  130.       switch(c) {
  131.  
  132.       case 'a':
  133.          archive_period = atoi( optarg );
  134.          break;
  135.  
  136.       case 'e':
  137.          expire_period = atoi( optarg );
  138.          break;
  139.  
  140.       case 'n':
  141.          group = optarg;
  142.          break;
  143.  
  144.       case 'x':
  145.          debuglevel = atoi( optarg );
  146.          break;
  147.  
  148.       case '?':
  149.          usage();
  150.          exit(1);
  151.          break;
  152.  
  153.       default:
  154.          printmsg(0, "expire - invalid option -%c", c);
  155.          usage();
  156.          exit(2);
  157.          break;
  158.    }
  159.  
  160.    if (optind != argc) {
  161.       fputs("Extra parameter(s) at end.\n", stderr);
  162.       usage();
  163.       exit(2);
  164.    }
  165.  
  166. /*--------------------------------------------------------------------*/
  167. /*                             Initialize                             */
  168. /*--------------------------------------------------------------------*/
  169.  
  170.    tzset();                      /* Set up time zone information  */
  171.  
  172.    if (!configure( B_NEWS ))
  173.       exit(1);   /* system configuration failed */
  174.  
  175. /*--------------------------------------------------------------------*/
  176. /*                  Switch to the spooling directory                  */
  177. /*--------------------------------------------------------------------*/
  178.  
  179.    PushDir( E_newsdir );
  180.    atexit( PopDir );
  181.  
  182. /*--------------------------------------------------------------------*/
  183. /*                     Initialize logging file                        */
  184. /*--------------------------------------------------------------------*/
  185.  
  186.    openlog( NULL );
  187.  
  188. /*--------------------------------------------------------------------*/
  189. /*                       Load the active file                         */
  190. /*--------------------------------------------------------------------*/
  191.  
  192.    get_active();              /* Get sequence numbers for groups from
  193.                                  active file                      */
  194.  
  195. /*--------------------------------------------------------------------*/
  196. /*                  Compute times for expiring files                  */
  197. /*--------------------------------------------------------------------*/
  198.  
  199.    time( &expire_date );
  200.    expire_date  -= (expire_period * ONE_DAY);
  201.    archive_date = expire_date - (archive_period * ONE_DAY);
  202.  
  203.    printmsg(1,"%s: %sing news older than %s (%ld days)",
  204.             argv[0],
  205.             archive_period ?  "Archiv" : "Purg",
  206.             dater( expire_date , NULL), (long) expire_period );
  207.  
  208.    if ( archive_period != 0 )
  209.       printmsg(1,"%s: Purging news older than %s",
  210.             argv[0],
  211.                   dater( archive_date , NULL));
  212.  
  213. /*--------------------------------------------------------------------*/
  214. /*    Process one group if requested, otherwise process the entire    */
  215. /*    active file                                                     */
  216. /*--------------------------------------------------------------------*/
  217.  
  218.       if ( group != NULL )
  219.          ExpireGroup( group, expire_date, archive_date );
  220.       else
  221.          ExpireAll(expire_date, archive_date );
  222.  
  223. /*--------------------------------------------------------------------*/
  224. /*                         Clean up and exit                          */
  225. /*--------------------------------------------------------------------*/
  226.  
  227.    put_active();
  228.  
  229.    if ( total_articles_purged || total_articles_archived)
  230.       printmsg(1,"%s: Purged %ld total articles (%ld bytes), "
  231.                     "archived %ld total articles (%ld bytes). " ,
  232.                   argv[0],
  233.                   total_articles_purged,   total_bytes_purged,